This script setup your linux light mode background screen.
Execute Command:
nano main.pyimport sys
from PyQt5.QtWidgets import (QApplication, QMainWindow, QWidget,
QVBoxLayout, QPushButton, QFileDialog,
QLabel, QMessageBox)
from PyQt5.QtGui import QPixmap
import os
import platform
# Import platform-specific modules if needed (e.g., ctypes for Windows)
import ctypes # Uncomment if specifically targeting Windows API
class WallpaperManagerApp(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("Local Wallpaper Manager")
self.setGeometry(100, 100, 1920, 1080)
# Central Widget and Layout
central_widget = QWidget()
self.setCentralWidget(central_widget)
layout = QVBoxLayout()
# Widgets
self.select_button = QPushButton("Select Wallpaper Image")
self.select_button.clicked.connect(self.select_image)
self.status_label = QLabel("Ready to select image...")
# Add widgets to layout
layout.addWidget(self.select_button)
layout.addWidget(self.status_label)
central_widget.setLayout(layout)
def select_image(self):
# Open a file dialog to select an image file
# Filter for common image types
file_path, _ = QFileDialog.getOpenFileName(
self,
"Select Wallpaper",
"",
"Image Files (*.jpg *.jpeg *.png *.bmp)"
)
if file_path:
self.status_label.setText(f"Selected: {file_path}")
# Step 3 will call the set_wallpaper function here
self.set_wallpaper(file_path)
def set_wallpaper(self, image_path):
# This function will contain the platform-specific logic
self.status_label.setText(f"Attempting to set wallpaper...")
system_name = platform.system().lower()
try:
if system_name == 'windows':
# Windows logic (requires ctypes, usually SystemParametersInfoW)
# You'll need to uncomment `import ctypes` above for this to work
SPI_SETDESKWALLPAPER = 20
path = os.path.abspath(image_path)
ctypes.windll.user32.SystemParametersInfoW(SPI_SETDESKWALLPAPER, 0, path, 3)
# For this initial guide, we'll simplify and show the concept
pass
elif system_name == 'darwin': # macOS
# macOS logic (often uses osascript)
script = f"osascript -e 'tell application \"Finder\" to set desktop picture to POSIX file \"{os.path.abspath(image_path)}\"'"
os.system(script)
pass
elif system_name == 'linux':
# Linux/Gnome logic (often uses gsettings)
command = f"gsettings set org.gnome.desktop.background picture-uri file://{os.path.abspath(image_path)}"
os.system(command)
pass
else:
# Fallback for unsupported/unknown systems
QMessageBox.warning(self, "Warning",
f"Wallpaper changing is not yet implemented for {platform.system()} or failed."
)
self.status_label.setText(f"Selection successful, but wallpaper not set.")
return
self.status_label.setText(f"Wallpaper set successfully: {os.path.basename(image_path)}")
except Exception as e:
QMessageBox.critical(self, "Error",
f"Failed to set wallpaper. Error: {e}"
)
self.status_label.setText(f"Failed to set wallpaper.")
def main():
app = QApplication(sys.argv)
window = WallpaperManagerApp()
window.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()Execute Script
python main.pyMake code modular. Make it work in dark mode.